import { ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus, } from "@nestjs/common";
import { Request,Response} from "express";

@Catch()
export class HttpExceptionFilter implements ExceptionFilter{
  catch(exception: unknown, host: ArgumentsHost) {
      const ctx =host.switchToHttp();
      const response =ctx.getResponse<Response>();
      const resquest =ctx.getRequest<Request>();
      const httpStatus=exception instanceof HttpException?exception.getStatus():HttpStatus.INTERNAL_SERVER_ERROR;
      const message=exception instanceof HttpException?exception.message:'内部错误';
      response.status(httpStatus).json({
        code:httpStatus,
        message,
      })
  }
    
    
}